import { request } from '@umijs/max';
import { PageResponse } from './index';

export interface ActivityInfo {
  id?: number;
  title: string;
  description: string;
  startTime: string;
  endTime: string;
  location?: string;
  type: 1 | 2 | 3;  // 1-线上活动,2-线下活动,3-直播活动
  status: 0 | 1 | 2 | 3;  // 0-未开始,1-进行中,2-已结束,3-已取消
  maxParticipants?: number;
  currentParticipants?: number;
  registrationDeadline?: string;
  famousPersonId: number;
}

export interface ActivityPageRequest {
  pageCurrent: number;
  pageSize: number;
  famousPersonId: number;
  keyword?: string;
  type?: number;
  status?: number;
}

export async function getActivityPage(params: ActivityPageRequest) {
  return request<PageResponse<ActivityInfo>>('/activity/page', {
    method: 'POST',
    data: params,
  });
}

export async function addActivity(data: Omit<ActivityInfo, 'id'>) {
  return request('/activity/back', {
    method: 'POST',
    data,
  });
}

export async function updateActivity(data: ActivityInfo) {
  return request('/activity/back', {
    method: 'PUT',
    data,
  });
}

export async function deleteActivity(idList: number[]) {
  const ids = idList.join(',');
  return request(`/activity/back/${ids}`, {
    method: 'DELETE',
  });
}

// 获取最新活动列表
export async function getLatestActivities(famousPersonId: number) {
  return request<ActivityInfo[]>('/activity/latest', {
    method: 'GET',
    params: { famousPersonId },
  });
}

// 获取活动详情
export async function getActivityDetail(id: number) {
  return request<ActivityInfo>(`/activity/${id}`, {
    method: 'GET',
  });
}
